#!/bin/sh

BROWSERPATH="LibreWolf"

_sock="/tmp/firefox.sock"

if [ -S "${_sock}" ]
then
    if [ ${#} -eq 0 ]
    then
        printf 'nw' | nc -NU "${_sock}"
    else
        printf '%s' "nw$(printf '|%s' "${@}")" | nc -NU "${_sock}"
    fi
else
    if ! pgrep -f '$BROWSERPATH' > /dev/null
    then
        exec $BROWSERPATH "${@}"
    fi
fi
